import { useMessage } from '@/hooks/useAppMessage'
import { useAxios } from '@hooks/useAxios'
import { API_CURRENT_URL, API_LOGIN_URL } from '@services/baseApi'
import { useMutation } from '@tanstack/react-query'

export const useLoginMutation = () => {
  const { http } = useAxios()
  const message = useMessage()

  return useMutation({
    /**
     * @param {object} res
     * @param {string} res.username
     * @param {string} res.password
     * @param {boolean} res.remember
     * @returns
     */
    mutationFn: async (data) => {
      return await http.post(API_LOGIN_URL, data)
    },
  })
}

export const useAccountUpdateMutation = () => {
  const { http } = useAxios()
  const message = useMessage()
  return useMutation({
    mutationFn: async (data) => await http.put(`${API_CURRENT_URL}`, data),
    onSuccess: () => {
      message.success('更新成功')
    },
  })
}
